package zut.edu.cs.network.io.object;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

import zut.edu.cs.network.io.Person;

public class ObjectOutputStreamDemo {

	public static void main(String[] args) {
		File file = new File("person1.txt");
		FileOutputStream file1;
		try {
			file1 = new FileOutputStream(file);
			ObjectOutputStream os = new ObjectOutputStream(file1);
			
			Person person = new Person();
			person.age = 18;
			person.name = "sweet";
			os.writeObject(person);
			
			os.close();
			file1.close();
			System.out.println("写入成功");
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

	}

}
